package com.im.controller;

import com.im.config.WebConfig;
import com.im.entity.JwtExcludePath;
import com.im.interceptor.JwtInterceptor;
import com.im.service.JwtExcludePathService;
import com.im.web.response.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * JWT 放行路径管理 API
 */
@Tag(name = "JWT 放行路径管理")
@RestController
@RequestMapping("/jwt-exclude")
public class JwtExcludePathController {

    @Autowired
    private JwtExcludePathService jwtExcludePathService;
    @Autowired
    private WebConfig webConfig; // **注入 WebConfig**

    /**
     * 获取所有放行路径
     */
    @Operation(description = "获取所有 JWT 放行路径")
    @GetMapping("/list")
    public Result<List<JwtExcludePath>> list() {
        return Result.success(jwtExcludePathService.list());
    }

    /**
     * 新增放行路径
     */
    @Operation(description = "新增 JWT 放行路径")
    @PostMapping("/add")
    public Result<String> add(@RequestBody JwtExcludePath path) {
        jwtExcludePathService.save(path);
        return Result.success("放行路径新增成功");
    }

    /**
     * 删除放行路径
     */
    @Operation(description = "删除 JWT 放行路径")
    @DeleteMapping("/delete/{id}")
    public Result<String> delete(@PathVariable Long id) {
        jwtExcludePathService.removeById(id);
        return Result.success("放行路径删除成功");
    }
    @Operation(description = "手动重新加载 JWT 放行路径")
    @PostMapping("/reload")
    public Result<String> reload() {
        webConfig.reloadExcludePaths();
        return Result.success("放行路径已重新加载");
    }

}
